import { router } from 'cmdrouter';
import { execa } from 'execa';

const { stdout, stderr } = process;
const execaOpts = Object.freeze({ stdout, stderr });

// watch the watch for frontends/web
router({ build, watch }).route();

async function watch(block?: string) {
	await bulidSrc(block, true);
}

async function build(block?: string) {
	await bulidSrc(block);
}

async function bulidSrc(block?: string, watch?: boolean) {
	const watchArgs = watch ? ["-w"] : [];
	if (!block || block == 'web') {
		console.log("Buliding Web =======");
		//web
		execa('./node_modules/.bin/rollup', ['-c', "./web/rollup.config.js", ...watchArgs], execaOpts)
		execa('./node_modules/.bin/pcss', ['-c', "./web/pcss.config.js", ...watchArgs], execaOpts)

	}
}